package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.DriverContext;
import org.zhadoop.stream.cql.exception.CQLException;
import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.hooks.SemanticAnalyzeHook;
import org.zhadoop.stream.cql.semanticanalyzer.DataSourceQueryArgumentsAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.SemanticAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;
import org.zhadoop.stream.cql.tasks.Task;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

/**
 * 创建数据源解析内容
 * 
 * @author zwd
 *
 */
public class DataSourceBodyContext extends ParseContext {

	private String dataSourceName;
	private String alia;
	private List<ExpressionContext> queryarguments;
	private ColumnNameTypeListContext schemaColumns;

	public DataSourceBodyContext() {
		queryarguments = Lists.newArrayList();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("DATASOURCE " + dataSourceName);
		sb.append("[");
		sb.append(" SCHEMA (" + schemaColumns.toString() + ")");
		sb.append(" QUERY(" + Joiner.on(", ").join(queryarguments) + ")");
		sb.append("]");
		if (alia != null) {
			sb.append(" " + alia);
		}
		return sb.toString();
	}

	@Override
	public Task createTask(DriverContext driverContext, List<SemanticAnalyzeHook> analyzeHooks) throws CQLException {
		return null;
	}

	@Override
	public SemanticAnalyzer createAnalyzer() throws SemanticAnalyzerException {
		return new DataSourceQueryArgumentsAnalyzer(this);
	}

	@Override
	protected void walkChild(ParseContextWalker walker) {
		
	}

	public String getDataSourceName() {
		return dataSourceName;
	}

	public void setDataSourceName(String dataSourceName) {
		this.dataSourceName = dataSourceName;
	}

	public String getAlia() {
		return alia;
	}

	public void setAlia(String alia) {
		this.alia = alia;
	}

	public List<ExpressionContext> getQueryarguments() {
		return queryarguments;
	}

	public void setQueryarguments(List<ExpressionContext> queryarguments) {
		this.queryarguments = queryarguments;
	}

	public ColumnNameTypeListContext getSchemaColumns() {
		return schemaColumns;
	}

	public void setSchemaColumns(ColumnNameTypeListContext schemaColumns) {
		this.schemaColumns = schemaColumns;
	}

}
